package com.mmall.Concurrency.example.aqs;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

@Slf4j
public class FutureExample {

    static class MyCallable implements Callable<String>{   //返回的类型是String
        @Override
        public String call() throws Exception {
            log.info("do sth in callable");
            Thread.sleep(5000);
            return "Done";
        }
    }
//
    public static void main(String[] args) throws Exception{
        ExecutorService service = Executors.newCachedThreadPool();
        Future<String> future = service.submit(new MyCallable());   //用future来接收返回的值
        log.info("do sth in main");
      //  Thread.sleep(1000);
        String result = future.get();
        log.info("result: {}" ,result);
    }

}
